<?php

/**
 * 默认控制器
 */
class Controller_Default extends Controller_Abstract
{
	function actionIndex()
    {
		$this->_view['title'] = 'Index';
    }
    
    function actionLogin()
    {
    	$this->_view['title'] = '用户登入';
    	if ($this->_context->isPOST())
    	{
    		try
    		{
    			$user = User::meta()->validateLogin($_POST['name'], $_POST['password']);
    			$this->_app->changeCurrentUser($user->aclData(), $user['name']);
    			if ($_POST['history'])
    			{
    				return $this->_redirect($_POST['history']);
    			}
    			else
    			{
    				return $this->_redirect(url('default::default/index'));
    			}
    		}
    		catch (AclUser_UsernameNotFoundException $ex)
    		{
    			return $this->_redirect(url('default::default/login', array('msg'=>'wrong')));
    		}
    		catch (AclUser_WrongPasswordException $ex)
    		{
    			return $this->_redirect(url('default::default/login', array('msg'=>'wrong')));
    		}
    	}
    }
    
    function actionLogout()
    {
    	$this->_view['title'] = '用户登出';
    	$this->_app->cleanCurrentUser();
    	return $this->_redirect(url('default::default/login'));
    }
}

